/**
 * User: alesj
 * Date: 2005.6.8
 * Time: 11:20:35
 * 
 * (C) Genera Lynx d.o.o.
 */

package com.generalynx.ecos.page;

import java.text.MessageFormat;

public class NumberPageScroll extends IndexPageScroll {

    private static final int DEFAULT_LIMIT = 25;

    private int limit;
    private int totalCount;

    public NumberPageScroll() {
        this(DEFAULT_LIMIT);
    }

    public NumberPageScroll(int limit) {
        this.limit = limit;
    }

    public int firstResult() {
        return currentIdentifier * getLimit();
    }

    public int getLimit() {
        return limit;
    }

    public boolean hasTotalCount() {
        return true;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public boolean isUsePageScroll() {
        return true;
    }

    public boolean isLast() {
        return (currentIdentifier == getTotalCount() / getLimit());
    }

    public String doTaskbar() {
        StringBuffer buffer = new StringBuffer();
        int i = 0;
        while(i * getLimit() < getTotalCount()) {
            buffer.append(MessageFormat.format(i == currentIdentifier ?
                                               BOLD_PATTERN :
                                               LINK_PATTERN,
                                               new Object[]{new Integer(i + 1), new Integer(i)})
            ).append(" ");
            i++;
        }
        return buffer.toString();
    }

}
